package com.guigu.www.controller.wangChenZhen;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.guigu.www.dao.bean.TMember;
import com.guigu.www.service.TMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author WangChenZhen
 * @since 2021-06-16
 */
@RestController
@CrossOrigin
public class TMemberController {

    @Autowired
    TMemberService service;

    @GetMapping("/TMemberLogin")
    public TMember login(String name,String password){
        EntityWrapper<TMember> wrapper=new EntityWrapper<TMember>();
        wrapper.eq("name",name);
        wrapper.eq("password",password);
        return service.selectOne(wrapper);
    }

    @PostMapping("/TMemberEnroll")
    public boolean enroll(@RequestBody TMember tMember){
        Date date=new Date();
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String strDate=dateFormat.format(date);
        tMember.setRegTime(strDate);
        tMember.setCreatetime(strDate);
        tMember.setFileNumber(new Integer(10000+service.selectOne(new EntityWrapper<TMember>().orderBy("id",false)).getId()+1).toString());
        return service.insert(tMember);
    }


    @PostMapping("/TMemberSet")
    public boolean setTMember(@RequestBody TMember tMember){
        Date date=new Date();
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        String strDate=dateFormat.format(date);
        tMember.setUpdatetime(strDate);
        return service.update(tMember,new EntityWrapper<TMember>().eq("id",tMember.getId()));
    }


    @GetMapping("/TMemberIsName")
    public Boolean isName(String name){
        EntityWrapper<TMember> wrapper=new EntityWrapper<TMember>();
        wrapper.eq("name",name);
        return service.selectOne(wrapper)!=null;
    }


}

